﻿// <![CDATA[
function AspId(elementId) {
    return $$(elementId).attr("id")
}

function $$(id, context) {
    var el = $("#" + id, context);
    if (el.length < 1)
        el = $("[id$=_" + id + "]", context);
    return el;
}
function showagreement(c) {
    var overlayscript = "<div id='ov1ay' class='modalBackground'></div>";
    $(document.body).append(overlayscript
        + "<div onclick='$(this).fadeOut(400,function(){$(\"#agrwrap\").remove();$(\"#ov1ay\").remove()})' id='agrwrap' style='-moz-border-radius: 12px;-webkit-border-radius: 12px;border: 3px solid #CCC;z-index:1020;position:fixed;vertical-align:middle;top:120px;left:" + ((windowWidth / 2) - 300) + "px;display:none;width:600px;overflow:hidden;height:400px;background-color:#FBFBFB'>"
        + "<div class='smallCloseX' style='position:relative;left:583px;float:none;top:0px' onclick='$(\"#agrwrap\").hide(\"drop\", { direction: \"up\" }, 500,function(){$(\"#agrwrap\").remove();$(\"#ov1ay\").animate({ opacity: 0.0 }, 900);$(\"#ov1ay\").remove();})'></div>"
        + "<div id='agrcont' style='padding-right:10px;padding-left:10px;height:380px;overflow-x:hidden;overflow-y:scroll;clear:both;'><br><br><br><div style='width:100px;height:100px;margin-top:120px;margin-left:auto;margin-right:auto'><img src='/images/loading/loading23.gif' alt='loading...' /></div></div></div>");
    $("#agrcont").load("/content/SiteAgreement.aspx?culture=" + c);
    $("#ov1ay").animate({ opacity: 0.4 }, 999);
    $("#agrwrap").show("drop", { direction: "up" }, 999);
}
function tweakLeftPosition(idealLeft, objWidth) {
    var winWidth = $(window).width();
    var objRight = parseInt(idealLeft) + parseInt(objWidth);
    var val;
    if (objRight > winWidth) { val = idealLeft - (objRight - winWidth); }
    else { val = idealLeft; }
    return val;
}
function tweakTopPosition(idealTop, objHeight) {
    /*needs to be more precise*/
    var winHeight = $(document).height();
    var objBottom = parseInt(idealTop) + parseInt(objHeight);
    var val;
    if (objBottom > winHeight) { val = winHeight - objHeight; }
    else { val = idealTop; }
    return val;
}
function initTinyMce(id, lang) {
    tinyMCE.init({
        mode: "exact",
        elements: id,
        theme: "advanced",
        plugins: "safari,pagebreak,style,save,advhr,advimage,advlink,emotions,insertdatetime,media,contextmenu,paste,directionality,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
        language: lang,
        entity_encoding: "named",
        theme_advanced_buttons1: "newdocument,|,undo,redo,|,forecolor,|,backcolor,|,bold,italic,underline,fontselect,fontsizeselect,|,justifyleft,justifycenter,justifyright,justifyfull,|,outdent,indent,|,hr",
        theme_advanced_buttons2: 'emotions',
        theme_advanced_buttons3: "",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_resizing: false
    });
}
function FCKUpdateLinkedField(id) {
    try {
        if (typeof (FCKeditorAPI) == "object") {
            FCKeditorAPI.GetInstance(id).UpdateLinkedField();
        }
    }
    catch (err) {
    }
}
function editorContent() {
    return tinyMCE.activeEditor.getContent();
}
function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + encodeURI(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}
function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function InsertEmoticon(iconCode, objId) {
    txtDefaut = "";
    description = "";

    //couleur ou boîte de dialogue :	
    msg = "";

    text1 = ' ' + iconCode + ' '; //tag d'ouverture

    //	if(!tt)
    { // initialisation
        tt = document.getElementById(objId);
        moz = tt.selectionStart || tt.selectionStart == 0 ? 1 : 0; // Moz 1.6+, Firefox
        ie = document.selection ? 1 : 0; // IEWin, Opéra
    }
    tt.focus();

    // sélection de texte :
    txt = moz ? tt.value.substring(tt.selectionStart, tt.selectionEnd) :
			ie ? document.selection.createRange().text : '';

    if (ie) {
        var sel = document.selection.createRange();
        //remplace le contenu du textarea
        sel.text = text1 + txt
        sel.select(); //place le curseur juste après text2
    }
    else if (moz) {
        debut = tt.value.substring(0, tt.selectionStart);
        fin = tt.value.substring(tt.selectionEnd, tt.value.length);
        contenuScrollTop = tt.scrollTop; //sauve le scroll
        //remplace le contenu du textarea
        tt.value = debut + text1 + txt + fin;
        //place le curseur comme IE
        tt.selectionEnd = tt.selectionStart = (debut + text1 + txt).length;
        //empèche le scroll
        tt.scrollTop = contenuScrollTop;
    }
    else { // anciens navigateurs, curseur à la fin de la fenêtre d'édition
        tt.value = tt.value + text1;
    }

    text = tt.value;
};

//add a message box with no prompt to the top-left corner 
//se is the number of seconds before the dialog close itself.
//if se is omitted, a closed box with an X will be displayed so
//the user can close the message box manually
function addSysMsg(msg, se) {
    var d = new Date();
    var id = "msg" + makeId();
    var str = "<div id='" + id + "' onclick=\"$(this).slideFadeToggle('slow');\" class='sysMsg ui-widget'><div class='ui-state-highlight ui-corner-all' style='padding: 0 .7em;'>";
    if (se == undefined) {
        var close = "<div style=\"top:0;left:8px\" onclick='$(\"#" + id + "\").slideFadeToggle(1000,function(){$(\"#" + id + "\").remove()})' class=\"smallCloseX\"></div>";
        str = str + close;
    }
    str = str + "<p><span class='ui-icon ui-icon-info' style='float: left; margin-right: .3em;'></span>" + msg + "</p></div></div>";
    $("#sysMsgs").append(str);
    $("#" + id).slideFadeToggle(500);
    if (se != undefined) {
        setTimeout("$('#" + id + "').slideFadeToggle('slow',function(){$('#" + id + "').remove()})", se * 1000);
    }
    return id;
}
function addSysWarning(msg) {
    alert(msg);
}
function addSysWarningUI(msg) {
    var d = new Date();
    var id = "msg" + makeId();
    var str = "<div id='" + id + "' onclick=\"$(this).slideFadeToggle('slow');\" class='sysMsg ui-widget'><div class='ui-state-highlight ui-corner-all' style='padding: 0 .7em;color:#AF0000;font-weight:bold'><p><span class='ui-icon ui-icon-info' style='float: left; margin-right: .3em;'></span>" + msg + "</p></div></div>";
    $("#sysMsgs").append(str);
    $("#" + id).slideFadeToggle(500);
    setTimeout("$('#" + id + "').slideFadeToggle('slow',function(){$('#" + id + "').remove()})", 7000);
    return id;
}
function addSysAlert(msg) {
    alert(msg);
}
function addSysAlertUI(msg) {
    var d = new Date();
    var id = "msg" + makeId();
    var str = "<div id='" + id + "' onclick=\"$(this).slideFadeToggle('slow');\" class='sysMsg ui-widget'><div class='ui-state-error ui-corner-all' style='padding: 0 .7em;'><p><span class='ui-icon ui-icon-alert' style='float: left; margin-right: .3em;'></span>" + msg + "</p></div></div>";
    $("#sysMsgs").append(str);
    $("#" + id).slideFadeToggle(500);
    setTimeout("$('#" + id + "').slideFadeToggle('slow',function(){$('#" + id + "').remove()})", 5000);
    return id;
}

// jQuery fadeToggle plugin
jQuery.fn.fadeToggle = function(s, fn) {
    return (this.is(":visible"))
    ? this.fadeOut(s, fn)
    : this.fadeIn(s, fn);

};
jQuery.fn.blindToggle = function(speed, easing, callback) {
    var h = this.height() + parseInt(this.css('paddingTop')) + parseInt(this.css('paddingBottom'));
    return this.animate({ marginTop: parseInt(this.css('marginTop')) < 0 ? 0 : -h }, speed, easing, callback);
};
jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
    return this.animate({ opacity: 'toggle', height: 'toggle' }, speed, easing, callback);
};
jQuery.fn.slideToggle = function(speed, easing, callback) {
    return this.animate({ height: 'toggle' }, speed, easing, callback);
};
//parse a date string formatted as yyyyy/mm/dd (dayname)
//returns a javascript date object
function parsedate(id) {
    var date = $("#" + id).val();
    var y = date.toString().substr(0, 4);
    var m = parseInt(date.toString().substr(5, 2)) - 1;
    var d = date.toString().substr(8, 2);
    var dateobj = new Date();
    dateobj.setFullYear(y, m - 1, d);
    return dateobj;
}
//parses and returns the number of milliseconds since midnight of January 1, 1970 according to universal time.
function parseDateUTC(id) {
    var date = $("#" + id).val();
    var y = date.toString().substr(0, 4);
    var m = parseInt(date.toString().substr(5, 2)) - 1;
    var d = date.toString().substr(8, 2);
    return Date.UTC(y, m, d, 0, 0, 0, 0);
}
$.fn.equalHeights = function(px) {
    $(this).each(function() {
        var currentTallest = 0;
        $(this).children().each(function(i) {
            if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
        });
        if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
        // for ie6, set height since min-height isn't supported
        if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({ 'height': currentTallest }); }
        $(this).children().css({ 'min-height': currentTallest });
    });
    return this;
};


String.prototype.endsWith = function(s) {
    var reg = new RegExp(s + "$");
    return reg.test(this);
}

String.prototype.startsWith = function(s) {
    var reg = new RegExp("^" + s);
    return reg.test(this);
}
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
};

function trim(strText) {
    var txt = new String(strText);
    return txt.trim();
}
function makeId() {
    return (Math.random() * 1000000).toString().substr(0, 6);
}
/* */

jQuery.fn.encHTML = function() {
    return this.each(function() {
        var me = jQuery(this);
        var html = me.html();
        me.html(html.replace(/&/g, '&').replace(/</g, '&lt;').replace(/>/g, '&gt;'));
    });
};

jQuery.fn.decHTML = function() {
    return this.each(function() {
        var me = jQuery(this);
        var html = me.html();
        me.html(html.replace(/&/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>'));
    });
};
//returns true if string is html encoded
jQuery.fn.isEncHTML = function(str) {
    if (str.search(/&/g) != -1 || str.search(/&lt;/g) != -1 || str.search(/&gt;/g) != -1)
        return true;
    else
        return false;
};
//html decode only if string is html encoded
jQuery.fn.decHTMLifEnc = function() {
    return this.each(function() {
        var me = jQuery(this);
        var html = me.html();
        if (jQuery.fn.isEncHTML(html))
            me.html(html.replace(/&/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>'));
    });
}


//flash objects
function fj_findObj(n, d) {
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = fj_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function fj_showHideLayers() {
    var i, p, v, obj, args = fj_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = fj_findObj(args[i])) != null) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
        obj.visibility = v;
    }
}

/* editor functions */
function myCustomCleanup(type, value) {
    if (type == "insert_to_editor") {
        value = value.replace(/&lt;/gi, "<");
        value = value.replace(/&gt;/gi, ">");
    }
    return value;
}
function myCustomSaveContent(element_id, html, body) {
    html = html.replace(/</gi, "&lt;");
    html = html.replace(/>/gi, "&gt;");
    return html;
}

function removeCheckBoxBorders() {
    var el = document.getElementsByTagName("input");
    for (i = 0; i < el.length; i++) {
        var type = el[i].getAttribute("type");
        if ((type == "checkbox") || (type == "radio")) {
            el[i].style.border = "none";
            if (el[i].className.substr(0, 6) == "roundC") {
                $("#" + el[i].id).removeClass("roundC21");
                $("#" + el[i].id).removeClass("roundC31");
                $("#" + el[i].id).removeClass("roundC41");
            }
        }
    }
}


var cookies;

function getCookies() {
    cookies = document.cookie.split('; ');
    for (i in cookies) {
        if (typeof cookies[i] == 'function')
            continue;
        cookies[i] = cookies[i].toString().split('=');
    }
}
getCookies();

function getCookie(name) {
    for (i in cookies) {
        if (typeof cookies[i] == 'function')
            continue;

        if (cookies[i][0] == name)
            return cookies[i][1];
    }

    return null;
}

function setCookie(name, value) {
    var argv = setCookie.arguments;
    var argc = setCookie.arguments.length;
    document.cookie = name + "=" + escape(value) + (argv[2] ? ("; expires=" + argv[2].toGMTString()) : '');

    for (i in cookies) {
        if (typeof cookies[i] == 'function')
            continue;

        if (cookies[i][0] == name)
            return cookies[i][1] = value;
    }
}
//new implementation
function caldays(m, y) {
    if (m == 01 || m == 03 || m == 05 || m == 07 || m == 08 || m == 10 || m == 12) {
        var dmax = 31;
        return dmax;
    }
    else if (m == 04 || m == 06 || m == 09 || m == 11) {
        var dmax = 30;
        return dmax;
    }
    else {
        if ((y % 400 == 0) || (y % 400 == 0 && y % 100 != 0)) {
            dmax = 29;
            return dmax;
        }
        else {
            dmax = 28;
        }
        return dmax;
    }
}	
// ]]>
